package grailsworkshop2012_1_g

class Trip {
    String name 
    String city
    Date startDate
    Date endDate
    String purpose
    String notes 
    
    /*Creando relación "one to many" entre la clase user y trip. 
     *Relación: |User|(1)<-----(*)|Trip|
     */
    static belongsto = [owner:User] 
    
    
    /*Creando relación "one to one" entre la clase trip y budget. 
     *Relación: |Trip|(1)<-----(1)|Budget|
     */
    Budget bugdet
    //static hasOne = [budget:Budget]  
    
    //Restricciones para esta clase: 
    static constraints = {
                
        name blank: false, size: 3..15, unique: true
        city blank: false
                
        startDate blank: false, min: new Date().previous()
        endDate(validator: { val, obj -> val >= obj.startDate })
        
        endDate blank: false, min: new Date()
        purpose blank: false, inList: ["Pleasure", "Education", "Business", "Scientific", "Political"]
        notes blank: false
        bugdet unique:true
    }
    
    String toString(){
        "${name}"
    }
    
    
}
